package com.frog.sqs;

import com.alibaba.fastjson.JSONObject;
import com.frog.framework.rekognition.FrogRekognitionClient;
import com.frog.framework.rekognition.annotation.EnableRekognition;
import com.frog.framework.s3.FrogS3Client;
import com.frog.framework.s3.annotation.EnableS3;
import com.frog.queue.starter.sns.FrogSnsClient;
import com.frog.queue.starter.sns.annotation.EnableSns;
import com.frog.queue.starter.sqs.FrogSqsClient;
import com.frog.queue.starter.sqs.annotation.EnableSqsListener;
import com.frog.queue.starter.sqs.annotation.SqsListener;
import com.frog.queue.starter.sqs.enums.MessageDeletionPolicy;
import com.frog.queue.starter.sqs.container.QueueMessageAcknowledgment;
import org.springframework.stereotype.Service;
import software.amazon.awssdk.services.rekognition.model.GetContentModerationResponse;
import software.amazon.awssdk.services.rekognition.model.StartContentModerationResponse;
import software.amazon.awssdk.services.sqs.model.Message;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @author wuqiong 2022/4/11
 * @description
 */
@Service
@EnableSqsListener
@EnableS3
@EnableSns
@EnableRekognition
public class MySqsListener {

//    @Autowired
//    private FrogSnsClient frogSnsClient;

//    @Autowired
//    private FrogSqsClient frogSqsClient;


    @SqsListener(queueUrl = "https://sqs.us-west-1.amazonaws.com/243194539745/qiong-queue.fifo",deletionPolicy = MessageDeletionPolicy.NEVER)
    public void oneEvent(Message message, QueueMessageAcknowledgment acknowledgment){
        System.out.println(System.currentTimeMillis() + " 线程名: " + Thread.currentThread().getName()+"--->>> currentTimeMillis ： "+ System.currentTimeMillis() +"Fifo message body " + message.body());
        boolean acknowledge = acknowledgment.acknowledge();

//        frogSnsClient.publishTopic(null,"arn:aws:sns:us-west-1:243194539745:qiong-topic",
//                message.body(),null,null,null);


        FrogSqsClient.sentStandardMessage(null,"https://sqs.us-west-1.amazonaws.com/243194539745/qiong-standard-queue",
                message.body(),null,null);
        FrogSqsClient.sentStandardMessage("https://sqs.us-west-1.amazonaws.com/243194539745/qiong-standard-queue",message.body());
        String bucketName = "amplify-frogandroiden-dev-181449-deployment181449-dev";
        String key = "public/frog/android/video/211223174352870.mp4";
        Boolean b = FrogS3Client.isExistObject(null, bucketName, key);
        System.out.println("default : "+JSONObject.toJSONString(b));


    }


    @SqsListener(queueUrl = "qiong-standard-queue")
    public void oneEvent1(Message message){

        System.out.println(System.currentTimeMillis() + " 线程名: " + Thread.currentThread().getName()+"--->>> Standard message body " + message.body());
//        System.out.println("--->>> message receiptHandle " + message.receiptHandle());
//        System.out.println("------------------------------------<<<<<<<<<<<<<<  ");

        FrogSnsClient.publishTopic(null,"arn:aws:sns:us-west-1:243194539745:qiong-topic",
                message.body(),null,null,null);

//        String bucketName = "frog-us-east-2-s3-inctest";
//        String key = "json_unsplit2/Frog_API_KDF_RedShift-1";
        String bucketName = "amplify-frogandroiden-dev-181449-deployment181449-dev";
        String key = "public/frog/android/video/211223174352870.mp4";
        Boolean b = FrogS3Client.isExistObject(null, bucketName, key);
        System.out.println("tow2 : "+JSONObject.toJSONString(b));

        String bucketNames = "amplify-frogandroiden-dev-181449-deployment181449-dev";
        String sourceImage = "public/frog/android/video/221017155956829.mp4";
        String TOPIC_ARN = "arn:aws:sns:us-east-1:071094189941:video_mediaConvert_start";
        String REK_ROLE_ARN = "arn:aws:iam::071094189941:role/Rekognition";
        StartContentModerationResponse response = FrogRekognitionClient.getStartContentModeration("one1", bucketNames, sourceImage, REK_ROLE_ARN, TOPIC_ARN);
        System.out.println(response.jobId());

        GetContentModerationResponse contentModerationResponse = FrogRekognitionClient.getContentModerationResponse(null, response.jobId());
        System.out.println(contentModerationResponse.jobStatus());
        System.out.println(contentModerationResponse.toString());


    }





}
